using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using GameEngine;
using GameEngine.Graphics;
using GameEngine.GameStateManagment;
using GameEngine.TileMap;
using GameEngine.Graphics.Light;



namespace Robot_War
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D Aim;
        //TileMap TileMap;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            graphics.PreferredBackBufferHeight = 768;
            graphics.PreferredBackBufferWidth = 1024;
            //graphics.IsFullScreen = true;
            //IsMouseVisible = true;
            graphics.ApplyChanges();
            this.Window.Title = "Robot War 0.03";

            //TileMap = new TileMap();

            


            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Camera.Init(spriteBatch, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
            GameStateManagment.Init(spriteBatch);
            GameStateManagment.LoadContent(this.Content);
            LightManager.Init(this.GraphicsDevice, this);
            LightManager.GraphicsDevice = this.GraphicsDevice;
            LightManager.QRC = new QuadRenderComponent(this);
            LightManager.LoadContent(this.Content);

            Aim = Content.Load<Texture2D>("Aim");
            //TileMap.LoadContent(this.Content);
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            Input.Update();
            GameStateManagment.Update();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            GameStateManagment.Draw();
            MouseState MS = Mouse.GetState();

            spriteBatch.Begin();
            spriteBatch.Draw(Aim, new Vector2(MS.X,MS.Y), Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
